from django.db import models
from user.models import User
# Create your models here.


"""书籍分类表"""
class Cate(models.Model):
    name = models.CharField(max_length=30,verbose_name="分类名字")
    class Meta:
        db_table = "tb_cate"
        verbose_name = '书籍分类表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


"""书籍表"""
class Book(models.Model):
    name = models.CharField(max_length=30,verbose_name="书籍名字")
    author = models.CharField(max_length=30,verbose_name="作者")
    title = models.CharField(max_length=500,verbose_name="书籍标题")
    yp = models.IntegerField(verbose_name="月票")
    url = models.CharField(max_length=526,verbose_name="图片路径")
    cate_id = models.ForeignKey(Cate,on_delete=models.CASCADE,verbose_name="所属分类")
    content = models.IntegerField(verbose_name="浏览量",default=1)

    class Meta:
        db_table = "tb_book"
        verbose_name = '书籍表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


"""章节表"""
class Section(models.Model):
    name = models.CharField(max_length=50,verbose_name="章节名字")
    book_id = models.ForeignKey(Book,on_delete=models.CASCADE,verbose_name="所属书籍")


    class Meta:
        db_table = "tb_section"
        verbose_name = '章节表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


"""内容表"""
class Content(models.Model):
    name = models.CharField(max_length=1000,verbose_name="内容")
    section = models.ForeignKey(Section,on_delete=models.CASCADE,verbose_name="所属章节")

    class Meta:
        db_table = "tb_content"
        verbose_name = '内容表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name



"""月票表"""
class Yp(models.Model):
    name = models.IntegerField(verbose_name="几个月票")
    price = models.IntegerField(verbose_name="价格")

    class Meta:
        db_table = "tb_yp"
        verbose_name = '月票表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


"""轮播图"""
class Lbt(models.Model):
    img = models.CharField(max_length=326,verbose_name="轮播图路由")

    class Meta:
        db_table = "tb_lbt"
        verbose_name = '轮播图'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.img

class Sq(models.Model):
    user_id = models.ForeignKey(User,on_delete=models.CASCADE,verbose_name="所属用户")
    book_id = models.ForeignKey(Book,on_delete=models.CASCADE,verbose_name="所属书籍")
    class Meta:
        db_table = "tb_sq"
        verbose_name = '书签'
        verbose_name_plural = verbose_name





